﻿using System.Collections;
using UnityEngine;

//------------------------------------------------------------
// shaco Framework
// Copyright © 2017-2021 chang.liu All rights reserved.
// Feedback: 449612236@qq.com
//------------------------------------------------------------

namespace shaco
{
    /// <summary>
    /// UI状态变化协程事件
    /// </summary>
    public class WaitForUIPreLoad<T> : WaitForUIBase<T, shaco.UIStateChangedEvents.OnUIPreLoadEvent> where T : UnityEngine.Component {}
    public class WaitForUIInit<T> : WaitForUIBase<T, shaco.UIStateChangedEvents.OnUIInitEvent> where T : UnityEngine.Component {}
    public class WaitForUIOpen<T> : WaitForUIBase<T, shaco.UIStateChangedEvents.OnUIOpenEvent> where T : UnityEngine.Component {}
    public class WaitForUIResume<T> : WaitForUIBase<T, shaco.UIStateChangedEvents.OnUIResumeEvent> where T : UnityEngine.Component {}
    public class WaitForUIHide<T> : WaitForUIBase<T, shaco.UIStateChangedEvents.OnUIHideEvent> where T : UnityEngine.Component {}
    public class WaitForUIClose<T> : WaitForUIBase<T, shaco.UIStateChangedEvents.OnUICloseEvent> where T : UnityEngine.Component {}
    public class WaitForUIRefresh<T> : WaitForUIBase<T, shaco.UIStateChangedEvents.OnUIRefreshEvent> where T : UnityEngine.Component {}
    public class WaitForUIBringToFront<T> : WaitForUIBase<T, shaco.UIStateChangedEvents.OnUIBringToFrontEvent> where T : UnityEngine.Component {}

    /// <summary>
    /// ui状态发生变化基类事件
    /// </summary>
    public class WaitForUIBase<T1, T2> : shaco.Base.BaseEventArg, IEnumerator where T1 : UnityEngine.Component where T2 : shaco.UIStateChangedEvents.OnUIStateChangedBaseEvent
    {
        public object Current => null;
        private bool _isCompleted = false;
        private string _uiKey = string.Empty;

        protected WaitForUIBase()
        {
            _uiKey = shaco.Base.Utility.ToTypeString<T1>();
            this.AddEvent<T2>((sender, arg) =>
            {
                if (arg.uiKey == _uiKey)
                    _isCompleted = true;
            });
        }

        public bool MoveNext()
        {
            return !_isCompleted;
        }

        public void Reset()
        {
            throw new System.NotImplementedException("WaitForUIBase Reset not implemented yet");
        }
    }
}